package com.foreverwin.jzymes.production.cnc.controller;

import com.foreverwin.jzymes.common.domain.AgvReqLog;
import com.foreverwin.jzymes.common.domain.CarrierScanLog;
import com.foreverwin.jzymes.common.domain.CncReqLog;
import com.foreverwin.jzymes.common.util.CarrierUtil;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.framework.util.ObjectMapperUtil;
import com.foreverwin.jzymes.production.cnc.service.ICncSfcPassAdviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/production/cnc")
public class CncSfcPassController {

    @Autowired
    ICncSfcPassAdviceService cncSfcPassAdviceService;

    /**
     * 一夹自动线过站
     *
     * @param cncReqLogJson
     * @return
     */
    @RequestMapping("/sfcPassByCarrier")
    public AjaxResult sfcPassByCarrier(@RequestBody String cncReqLogJson ){
        try{
            CncReqLog cncReqLog = ObjectMapperUtil.readValueForUnderscore( cncReqLogJson, CncReqLog.class );
            cncReqLog.setCarrier( CarrierUtil.buildCarrier( cncReqLog.getSite(), cncReqLog.getCarrier() ) );
            cncSfcPassAdviceService.sfcPassByCarrier( cncReqLog );
            return AjaxResult.success();
        }catch ( Exception e ){
            return AjaxResult.error( e.getMessage() );
        }
    }

    /**
     * 一夹手工线过站
     *
     * @param agvReqLogJson
     * @return
     */
    @RequestMapping("/sfcPassByTrayQty")
    public AjaxResult sfcPassByTrayQty(@RequestBody String agvReqLogJson ){
        try{
            AgvReqLog agvReqLog = ObjectMapperUtil.readValueForUnderscore( agvReqLogJson, AgvReqLog.class );
            cncSfcPassAdviceService.sfcPassByTrayQty( agvReqLog );
            return AjaxResult.success();
        }catch ( Exception e ){
            return AjaxResult.error( e.getMessage() );
        }
    }

}
